package dbcp;

import java.sql.Connection;
import java.sql.SQLException;

import org.apache.commons.dbcp.BasicDataSource;

public class DbcpTest {
	public static void main(String[] args) throws SQLException {
		BasicDataSource ds = new BasicDataSource();
		ds.setUrl("jdbc:oracle:thin:@zha-ita032-w7:1521:xe");
		ds.setDriverClassName("oracle.jdbc.OracleDriver");
		ds.setUsername("jason");
		ds.setPassword("233");
		ds.setMaxActive(2);	//指定连接的最大数
		
		final Connection connection1 = ds.getConnection();
		System.out.println(connection1);
		Connection connection2 = ds.getConnection();
		System.out.println(connection2);
		
		new Thread(){
			public void run() {
				try {
					Thread.sleep(2000);
					connection1.close();
				} catch (Exception e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
			};
		};
		
		Connection connection3 = ds.getConnection();
		System.out.println(connection3);
	}

}
